package com.hj.dapp.business.category.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hj.dapp.business.category.model.Category;
import com.hj.dapp.business.category.service.CategoryService;
import com.hj.dapp.common.request.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 胡奥程
 * @version 1.0
 * @date 2024/1/27
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping("/page")
    public IPage<Category> page(@RequestBody PageRequest<Category> pageRequest) {
        return categoryService.page(pageRequest);
    }

    @GetMapping("/get/{id}")
    public Category get(@PathVariable("id") Long id) {
        return categoryService.get(id);
    }

    @PutMapping("/save")
    public void save(@RequestBody Category category) {
        categoryService.save(category);
    }
    @PostMapping("/edit")
    public void edit(@RequestBody Category category) {
        categoryService.edit(category);
    }
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        categoryService.delete(id);
    }
    @GetMapping("/list")
    public List<Category> list() {
        return categoryService.list();
    }
}
